import { LogHelper } from "../../utils/logHelper";

/**
 * 外矿守护者
 */
export class OuterOreProtectTask implements IOuterOreTask{
  run(room: Room, closestRoom: Room): void {
    if(room){
      let role = "defender";
      const creeps =  Object.values(Memory.creeps).filter((c) => c.role === role && c.outerRoom && c.outerRoom === room.name);
      const queue = closestRoom.spawnQueueGetRole(role,(c)=> c.memory.outerRoom !== undefined && c.memory.outerRoom === room.name);
      const spawn = closestRoom.spawn();
      if(creeps.length === 0 && queue.length === 0 && spawn && !spawn.spawning){
          let body = closestRoom.calculateCreepBody({
            [TOUGH]: 0.1,
            [MOVE]: 0.2,
            [HEAL]: 0.2,
            [RANGED_ATTACK]: 0.5,
          });
          closestRoom.spawnQueueAdd(role,body,{ role, bornRoom:closestRoom.name, outerRoom:room.name});
          LogHelper.log(`外矿房间管理[${room.name}] 申请孵化 ${role}`);
      }
    }
  }
}